// pages/settings/modifybuyer/modifybuyer.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    name: '',
    id: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.setData({
      name: options.name,
      id: options.id
    })
  },
  showTopTips: function() {
    var that = this;
    this.setData({
      showTopTips: true
    });
    setTimeout(function() {
      that.setData({
        showTopTips: false
      });
    }, 1500);
  },


  sub: function(e) {
    if (e.detail.value.input == '') {
      this.showTopTips();
      return;
    }
    if (e.detail.value.input == this.data.name) {
      wx.showToast({
        title: '请修改姓名',
        icon:'none',
      })
      return;
    }

    var that = this
    wx.request({
      url: 'http://192.168.3.2/cloudwarehouse/settings/buyer/buyermanagement/modifybuyer.php',
      data: {
        name: e.detail.value.input,
        id: that.data.id
      },
      header: {
        'content-type': 'application/json'
      },
      success(res) {
        console.log(res)
        wx.showToast({
          title: '更改成功',
        })
        setTimeout(function(){
          wx.navigateBack({
            delta: 1
          })
        },1000)
       
      }

    })

  },

  del: function () {
    var that = this
    wx.showModal({
      title: '确认删除',
      content: '确认要删除这个人吗？',
      confirmText: "确认",
      cancelText: "取消",
      confirmColor:'#e64340',
      success: function (res) {
        if (res.confirm) {
          wx.request({
            url: 'http://192.168.3.2/cloudwarehouse/settings/buyer/buyermanagement/deletebuyer.php',
            data:{id : that.data.id},
            success(res) {
              console.log(res)
              wx.showToast({
                title: '删除成功',
              })
              setTimeout(function () {
                wx.navigateBack({
                  delta: 1
                })
              }, 1000)
            }
          })
        }
      }
    });
  },



  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})